<template>
<!--面包屑-->
<div style="margin-bottom: 30px;">
  <el-breadcrumb separator="/">
    <el-breadcrumb-item :to="{ path: '/Main' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>
      <router-link to="/MenuModule/MenuDisplay">菜单管理</router-link>
    </el-breadcrumb-item>
    <el-breadcrumb-item>菜单列表</el-breadcrumb-item>
  </el-breadcrumb>
</div>

<div style="margin-bottom: 15px;">
  <el-button type="primary" @click="router.push('AddRoleModule')">新增</el-button>&nbsp;&nbsp;
  <el-button type="primary" @click="delRange">批量删除</el-button>&nbsp;&nbsp;
</div>

<!--物资列表-->
<div>
  <el-table :data="UserInfoData" border style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" />
      <el-table-column prop="id" label="编号" align="center" />
      <el-table-column prop="menu_name" label="菜单名称" align="center" width="109px" />
      <el-table-column prop="menu_url" label="菜单Url" align="center" />
      <!-- <el-table-column prop="menu_icon" label="菜单图标" align="center" /> -->
      <el-table-column prop="pid" label="父级菜单名称" align="center" />
      <!-- <el-table-column prop="order_num" label="排序" align="center" /> -->
      <el-table-column prop="perms" label="授权" align="center" />
      <el-table-column prop="type	" label="员工类别" align="center" >
        <template #default="scope">
          <span v-if="scope.row.type	 == 1">目录</span>
          <span v-else-if="scope.row.type	 == 2">菜单</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="create_by" label="创建人" align="center" /> -->
      <el-table-column prop="create_date" label="创建时间" align="center" width="162px" >
        <template #default="scope">
          {{ scope.row.create_date.replace("T"," ").substr(0,19) }}
        </template>
      </el-table-column>
      <!-- <el-table-column prop="update_by" label="修改人" align="center" /> -->
      <el-table-column prop="update_date" label="修改时间" align="center" />
      <el-table-column prop="remarks" label="评论" align="center" />
      <el-table-column label="操作" align="center" >
        <template v-slot=scope>
          <el-button type="primary" @click="router.push('UpdateMenuDisplay?id='+scope.row.id)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
</div>
  
  <!--分页-->
  <div>
    <table>
    <thead></thead>
    <tbody>
      <tr>
        <td>
          <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[3, 5, 7, 9]" :background="true" layout="total,slot, sizes" :total="form.totalCount" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
            <span>
              ，每页{{ form.pageSize }}条，当前第:{{ form.pageIndex }}/{{ form.totalPage }}页
            </span>
          </el-pagination>
        </td>
  
        <td>
          <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[100, 200, 300, 400]" :background="true" layout="slot, prev, pager, next" :total="form.totalCount" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
            <el-button type="primary" class="btn-prev" @click="handleCurrentChange(1)" :disabled="form.pageIndex==1">首页</el-button>
          </el-pagination>
        </td>
  
        <td>
          <el-pagination v-model:current-page="form.pageIndex" v-model:page-size="form.pageSize" :page-sizes="[100, 200, 300, 400]" :background="true" layout="slot, jumper" :total="form.totalCount" prev-text="上一页" next-text="下一页" @size-change="handleSizeChange" @current-change="handleCurrentChange">
            <el-button type="primary" class="btn-prev" @click="handleCurrentChange(form.totalPage)" :disabled="form.pageIndex==form.totalPage">尾页</el-button>
          </el-pagination>
        </td>
      </tr>
    </tbody>
  </table>
  </div>
  </template>
  
  <script setup lang="ts">
  import { reactive, ref, onMounted, computed } from 'vue'
  import axios from 'axios';
  import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
  import { ElMessage, ElMessageBox } from 'element-plus'
  
  import {useRoute,useRouter} from 'vue-router'
  
  const route = useRoute();
  const router = useRouter();
  const dialogFormVisible:any = ref(false)
const formLabelWidth = '140px'
const formSize = ref<ComponentSize>('default')

  
  onMounted(() => {
    //用户列表
    getUserInfoList()
  })
  
  const form: any = reactive({
    pageIndex: 1,
    pageSize: 15,
    totalPage: 0,
    totalCount: 0,
  })

  //存储多选中的物资id
const multipleSelection:any = ref([]);
  const handleSelectionChange = (val: any) => {
    // console.log(val);
    multipleSelection.value = val;
  }
  
  
  //分页
  const handleSizeChange = (val: number) => {
    form.pageSize = val;
    getUserInfoList()
  }
  const handleCurrentChange = (val: number) => {
    form.pageIndex = val;
    getUserInfoList()
  }
  
  //用户列表
  const UserInfoData:any=ref([])
  const getUserInfoList = () => {
  
    axios.get('http://1.117.93.87:8000/rbacdu/api/Menu/MenuShow', {
      params: {
        pageIndex: form.pageIndex,
        pageSize: form.pageSize,
      }
    }).then(res=>{
      console.log(res.data.data);
      UserInfoData.value = res.data.data.list;
      form.totalPage = res.data.data.totalPage;
      form.totalCount = res.data.data.totalCount;
    }).catch(err=>{
      console.log(err);
      
    })    
  }


//批量删除
  const delRange = () => {
    let ids = multipleSelection.value.map((x: any) => x.id);
  if (ids.length == 0) {
    ElMessage.error("请至少选择一条要删除的菜单信息!")
    return
  }

  ElMessageBox.confirm(
    '确认删除这些菜单信息吗?',
    '确认删除',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
    }
  )
    .then(() => {
      axios.post('http://1.117.93.87:8000/rbacxie/api/Menu/menuDelete', {
        materialStoreId: ids,
      }).then(res => {
        console.log(res);
        if (res.data.code >= 0) {
          ElMessage.success("删除成功!")
          //刷新页面
          getUserInfoList()
        } else {
          ElMessage.error("删除失败!")
          return
        }
      }).catch(err => {
        console.log(err);

      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '取消操作',
      })
    })
}

  </script>
  
  <style scoped>
  
  </style>